﻿@{
    ViewData["Title"] = "WCS历史任务";
    ViewData["Mbx"] = "任务管理";
    Layout = "_Default";
}
<link rel="stylesheet" type="text/css" href="~/css/buttons.css" />
<link href="~/lib/Hui-iconfont/1.0.8/iconfont.css" rel="stylesheet" type="text/css" />
@section css {
    <style>

        .fliter {
            /*width: 80%;*/
            height: 40px;
            align-items: center;
            display: flex;
            margin-bottom: 10px;
        }

        .add {
            width: 80%;
            height: 60px;
            align-items: center;
            display: flex;
        }

        .fliter .search-btn {
            margin-left: 20px;
        }

        .fliter .input-text {
            width: 200px;
        }

        .fliter .label-eq-name {
            margin-left: 20px;
            text-align: justify;
            width: 107px;
        }

        .fliter .label-eq-code {
            margin-left: 20px;
        }

        .btn-add {
            margin-left: 20px;
        }

        div.dataTables_wrapper .dataTables_length {
            float: none;
        }

        .select-box {
            width: 200px
        }

        .button-rounded {
            padding: 5px 10px;
        }
    </style>
}
@section gray {

    <div class="fliter">
        <label class="label-eq-name">WMS起始工位：</label>
        <input type="text" class="input-text" value="" placeholder="请输入WMS起始工位" id="WmsFromStation" name="WmsFromStation">
        <label class="label-eq-code">WMS目标工位：</label>
        <input type="text" class="input-text" value="" placeholder="请输入WMS目标工位" id="WmsToStation" name="WmsToStation">
        <label class="label-eq-name">WMS起始位置：</label>
        <input type="text" class="input-text" value="" placeholder="请输入WMS起始位置" id="WmsFromPosition" name="WmsFromPosition">
        <label class="label-eq-name">WMS目标位置：</label>
        <input type="text" class="input-text" value="" placeholder="请输入WMS目标位置" id="WmsToPosition" name="WmsToPosition">
        <label class="label-eq-name">托 盘 编 码：</label>
        <input type="text" class="input-text" value="" placeholder="请输入托盘编码" id="PalletCode" name="PalletCode">
        <label class="label-eq-name">工 作 状 态：</label>
        <span class="select-box">
            <select class="select" size="1" name="TaskState" id="TaskState">
                @*<option value="-1" selected>--请选择--</option>*@
                @foreach (var item in @Model.TaskStates)
                {
                    <option value="@item.TaskStateValue">@item.TaskStateName</option>
                }
            </select>
        </span>
    </div>
    <div class="fliter">
        <label class="label-eq-name">任务 编 码：</label>
        <input type="text" class="input-text" value="" placeholder="请输入任务编码" id="TaskCode" name="TaskCode">
        <label class="label-eq-name">起 始 工 位：</label>
        <input type="text" class="input-text" value="" placeholder="请输入起始工位" id="FromStation" name="FromStation">
        <label class="label-eq-name">目 标 工 位：</label>
        <input type="text" class="input-text" value="" placeholder="请输入目标工位" id="ToStation" name="ToStation">
        <label class="label-eq-name">WMS任务编码：</label>
        <input type="text" class="input-text" value="" placeholder="请输入WMS任务编码" id="WmsTaskCode" name="WmsTaskCode">
        <label class="label-eq-name">任 务 类 型：</label>
        <span class="select-box">
            <select class="select" size="1" name="TaskType" id="TaskType">
                @*<option value="-1" selected>--请选择--</option>*@
                @foreach (var item in @Model.TaskTypes)
                {
                    <option value="@item.TaskTypeValue">@item.TaskTypeName</option>
                }
            </select>
        </span>
        <label class="label-eq-name">WMS上传状态：</label>
        <span class="select-box">
            <select class="select" size="1" name="UploadState" id="UploadState">
                @*<option value="-1" selected>--请选择--</option>*@
                @foreach (var item in @Model.UploadWmsStates)
                {
                    <option value="@item.UploadWmsStateValue">@item.UploadWmsStateName</option>
                }
            </select>
        </span>

    </div>


    <div class="fliter">
        

        @*  <label class="label-eq-name">任务处理状态：</label>
    <span class="select-box">
    <select class="select" size="1" name="TaskProcessState" id="TaskProcessState">
    <option value="-1" selected>--请选择--</option>*
    @foreach (var item in @Model.TaskProcStates)
    {
    <option value="@item.TaskProcessStateValue">@item.TaskProcessStateName</option>
    }
    </select>
    </span>*@

        <label class="label-eq-name">巷道：</label>
        <span class="select-box">
            <select class="select" size="1" name="RouteInfo" id="RouteInfo">

                @foreach (var item in @Model.ScItems)
                {
                    <option value="@item.ScValue">@item.ScName</option>
                }
            </select>
        </span>
        <label class="label-eq-name">当前调度类型：</label>
        <span class="select-box">
            <select class="select" size="1" name="CurrentDispatchType" id="CurrentDispatchType">


                <option value="0">请选择</option>
                <option value="1">平面设备</option>
                <option value="2">堆垛机入库</option>
                <option value="3">堆垛机出库</option>

            </select>
        </span>
        <label class="label-eq-name">  创建时间：</label>
        <input type="text" class="input-text Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm', maxDate:'#F{$dp.$D(\'endTime\')||\'%y-%M-%d %H:%m\'}' })" id="startTime">---
        <input type="text" class="input-text Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',minDate:'#F{$dp.$D(\'startTime\')}',maxDate:'%y-%M-%d %H:%m'})" id="endTime">

        @*<input class="btn btn-primary radius search-btn" type="button" onclick="createnewtask()" value="&nbsp;&nbsp;创建新任务&nbsp;&nbsp;">*@
    </div>
    <div class="fliter">

        <input class="btn btn-primary radius search-btn" type="button" onclick="search()" value="&nbsp;&nbsp;搜索&nbsp;&nbsp;">
    </div>
}
<table class="table table-border table-bordered table-hover table-bg table-sort" style="background-color: #FFFFFF;">
    <thead>
    </thead>
    <tbody>
    </tbody>
</table>

@section javascript {
    <script type="text/javascript" src="~/lib/My97DatePicker/4.8/WdatePicker.js"></script>
    <script>
        $(function () {
            initData("", "", "", "", "", "", "", 0, 0, -1, -1, -1, "", "", "", -1);
        });

        function search() {
            var FromStation = $("#FromStation").val();
            var ToStation = $("#ToStation").val();
            var WmsFromStation = $("#WmsFromStation").val();
            var WmsToStation = $("#WmsToStation").val();
            var WmsFromPosition = $("#WmsFromPosition").val();
            var WmsToPosition = $("#WmsToPosition").val();
            var PalletCode = $("#PalletCode").val();
            var TaskCode = $("#TaskCode").val();
            var WmsTaskCode = $("#WmsTaskCode").val();
            var TaskType = $("#TaskType").val();
            var TaskState = $("#TaskState").val();
            var TaskProcessState = -1;
            var RouteInfo = $("#RouteInfo").val();
            var StartTime = $("#startTime").val();
            var EndTime = $("#endTime").val();
            var UploadWmsState = $("#UploadState").val();
            initData(FromStation, ToStation, WmsFromStation, WmsToStation, WmsFromPosition, WmsToPosition, PalletCode, TaskCode, WmsTaskCode, TaskType, TaskState, TaskProcessState, RouteInfo, StartTime, EndTime, UploadWmsState);
        }

        function initData(FromStation, ToStation, WmsFromStation, WmsToStation, WmsFromPosition, WmsToPosition, PalletCode, TaskCode, WmsTaskCode, TaskType, TaskState, TaskProcessState, RouteInfo, StartTime, EndTime, UploadWmsState) {
            $('.table-sort').dataTable({
                bProcessing: true, //DataTables 载入数据时，是否显示‘进度’提示
                bAutoWidth: true, //自动宽度
                bSort: false, //排序功能
                sScrollX: true, //横向滑动
                paging: true, //是否分页
                bInfo: true, //页脚信息,默认为 true
                bStateSave: false, //状态保存
                sPaginationType: "full_numbers", //分页显示样式
                serverSide: true, //启用服务器分页
                //sAjaxSource: "/admin/functionlist", //服务端请求数据接口
                searching: false, //关闭 datatables 的搜索框
                destroy: true, //解决重新渲染问题
                iDisplayLength: 10, //每页显示数量
                ajax: {
                    url: "/historyworktaskinfo/getallworktaskinfo",
                    type: "POST",
                    contentType: "application/x-www-form-urlencoded",
                    async: false,
                    dataType: "json",
                    data: function (data) {
                        data.FromStation = FromStation;
                        data.ToStation = ToStation;
                        data.WmsFromStation = WmsFromStation;
                        data.RouteInfo = RouteInfo;
                        data.WmsToStation = WmsToStation;
                        data.WmsFromPosition = WmsFromPosition;
                        data.WmsToPosition = WmsToPosition;
                        data.PalletCode = PalletCode;
                        data.TaskCode = TaskCode;
                        data.WmsTaskCode = WmsTaskCode;
                        data.TaskType = TaskType;
                        data.TaskState = TaskState;
                        data.TaskProcessState = TaskProcessState;
                        data.startTime = StartTime;
                        data.endTime = EndTime;
                        data.CurrentDispatchType = $("#CurrentDispatchType").val();
                        data.UploadWmsState = UploadWmsState;
                    },
                    dataFilter: function (json) {
                        console.log(json);
                        return json;
                    }
                },

                aoColumns: [
                    // mDataProp：绑定数据属性
                    // sDefaultContent：设置默认值
                    // sClass：添加 class 属性，不懂的直接去掉
                    // sTtile：设置列标题
                    // sWidth：设置列宽度
                    // sTtile 设置的内容，会替换到 html thead 中的“标题”
                    //{mDataProp:"js_Id", sClass:"text-c",  sTitle:"编号",sDefaultContent:""},
                    //{mDataProp:"js_Id", sClass:"text-c", sTitle:"ID",sDefaultContent:"",sWidth:"150px"},
                    { mDataProp: "routeInfo", sClass: "text-c", sTitle: "路径", sDefaultContent: "", sWidth: "150px" },
                    { mDataProp: "priority", sClass: "text-c", sTitle: "优先级", sDefaultContent: "", sWidth: "50px" },
                    { mDataProp: "palletCode", sClass: "text-c", sTitle: "托盘编码", sDefaultContent: "", sWidth: "120px" },
                    { mDataProp: "taskCode", sClass: "text-c", sTitle: "任务编码", sDefaultContent: "", sWidth: "100px" },
                    { mDataProp: "taskTypeFormat", sClass: "text-c", sTitle: "任务类型", sDefaultContent: "", sWidth: "100px" },
                    { mDataProp: "taskProcessStateFormat", sClass: "text-c", sTitle: "处理状态", sDefaultContent: "", sWidth: "120px" },
                    { mDataProp: "taskStateFormat", sClass: "text-c", sTitle: "工作状态", sDefaultContent: "", sWidth: "120px" },
                    { mDataProp: "saveTimeFormat", sClass: "text-c", sTitle: "创建时间", sDefaultContent: "", sWidth: "150px" },
                    { mDataProp: "updateTimeFormat", sClass: "text-c", sTitle: "更新时间", sDefaultContent: "", sWidth: "150px" },
                    { mDataProp: "wmsTaskCode", sClass: "text-c", sTitle: "WMS依赖任务编码", sDefaultContent: "", sWidth: "120px" },
                    //{mDataProp:"wmsFromStation",  sClass:"text-c", sTitle:"WMS起始工位",sDefaultContent:"",sWidth:"80px"},
                    //{mDataProp:"wmsToStation",  sClass:"text-c", sTitle:"WMS目标工位",sDefaultContent:"",sWidth:"80px"},
                    { mDataProp: "wmsFromPosition", sClass: "text-c", sTitle: "WMS起始位置", sDefaultContent: "", sWidth: "200px" },
                    //{mDataProp:"wmsToPosition",  sClass:"text-c", sTitle:"WMS目标位置",sDefaultContent:"",sWidth:"100px"},
                    { mDataProp: "uploadWmsStateFormant", sClass: "text-c", sTitle: "WMS上传状态", sDefaultContent: "", sWidth: "100px" },
                    { mDataProp: "uploadWmsTimeFormat", sClass: "text-c", sTitle: "上传WMS时间", sDefaultContent: "", sWidth: "150px" },
                    { mDataProp: "currentDetailTaskStateFormat", sClass: "text-c", sTitle: "当前节点状态", sDefaultContent: "", sWidth: "80px" },
                    { mDataProp: "dispatchTypeDescription", sClass: "text-c", sTitle: "当前节点调度类型", sDefaultContent: "", sWidth: "80px" },
                    { mDataProp: "currentFromEquipment", sClass: "text-c", sTitle: "当前节点起始设备", sDefaultContent: "", sWidth: "80px" },
                    {
                        mDataProp: "currentFromCargo", sClass: "text-c", sTitle: "当前节点起始货位", sDefaultContent: "", sWidth: "150px",
                        mRender: function (data, type, row) {
                            if (data != null && data != "" && row.currentFromCargo.substr(10, 1)) {

                                var paist = parseInt(row.currentFromCargo.substr(1, 3));
                                var paiInt = paist % 2 == 0 ? 2 : 1;
                                var paiStr = paiInt + " 排 "
                                var lie = parseInt(row.currentFromCargo.substr(4, 3));
                                var ceng = parseInt(row.currentFromCargo.substr(7, 3));
                                ///拼接楼排列层数据
                                var info = paiStr + lie + " 列 " + ceng + " 层 ";
                                return data + "<br>" + info;
                            }
                            else {
                                return "";
                            }

                        }
                    },



                    { mDataProp: "currentToEquipment", sClass: "text-c", sTitle: "当前节点目标设备", sDefaultContent: "", sWidth: "80px" },




                    {
                        mDataProp: "currentToCargo", sClass: "text-c", sTitle: "当前节点目标货位", sDefaultContent: "", sWidth: "150px",
                        mRender: function (data, type, row) {
                            if (data != null && data != "" && row.currentToCargo.substr(10, 1)) {

                                var paist = parseInt(row.currentToCargo.substr(1, 3));
                                var paiInt = paist % 2 == 0 ? 2 : 1;
                                var paiStr = paiInt + " 排 "
                                var lie = parseInt(row.currentToCargo.substr(4, 3));
                                var ceng = parseInt(row.currentToCargo.substr(7, 3));
                                ///拼接楼排列层数据
                                var info = paiStr + lie + " 列 " + ceng + " 层 ";
                                return data + "<br>" + info;
                            }
                            else {
                                return "";
                            }

                        }
                    },




                    { mDataProp: "currentCreateTimeFormat", sClass: "text-c", sTitle: "当前节点创建时间", sDefaultContent: "", sWidth: "150px" },
                    { mDataProp: "currentUpdateTimeFormat", sClass: "text-c", sTitle: "当前节点更新时间", sDefaultContent: "", sWidth: "150px" },

                    {
                        mDataProp: "js_Id", sClass: "text-c", sTitle: "操作", sWidth: "180px",
                        mRender: function (data, type, row) {
                            var html = "<a title=\"还原任务\" href=\"javascript:;\" onclick=\"backSetTask('" + data + "','" + row.palletCode + "','" + row.wmsTaskCode + "')\" class=\"ml-5 btn btn-success-outline radius\" style=\"text-decoration:none; margin-left:15px;\">还原任务</a>";
                            // html += "<a title=\"完成当前节点任务\" href=\"javascript:;\" onclick=\"CompleteWorkTaskStatusAsync('" + data + "','" + row.dispatchTypeDescription + "')\" class=\"ml-5 btn btn-secondary-outline radius\" style=\"text-decoration:none; margin-left:15px;\">完成任务</a>";
                            // html += "<a title=\"重置任务\" href=\"javascript:;\" onclick=\"ResetWorkTaskInfoAsync('" + data + "')\" class=\"ml-5 btn btn-warning-outline radius\" style=\"text-decoration:none; margin-left:15px;\">重置任务</a>";
                            // html += "<a title=\"删除任务\" href=\"javascript:;\" onclick=\"DelWorkTaskInfoAsync('" + data + "','" + row.palletCode + "')\" class=\"ml-5 btn btn-danger-outline radius\" style=\"text-decoration:none; margin-left:15px;\">删除任务</a>";
                            // if ((row.taskState == 0 || row.taskState == 2) && row.currentDetailTaskState == 0 && row.priority != 9999) {
                            //     html += "<a title=\"置顶任务\" href=\"javascript:;\" onclick=\"TopWorkTaskInfoAsync('" + data + "','" + row.palletCode + "')\" class=\"ml-5 btn btn-warning-outline radius\" style=\"text-decoration:none; margin-left:15px;\">置顶任务</a>";
                            // } else if (row.priority == 9999) {
                            //     html += "<a title=\"置顶任务\" href=\"javascript:;\" onclick=\"CanselTopWorkTaskInfoAsync('" + data + "','" + row.palletCode + "')\" class=\"ml-5 btn btn-secondary-outline radius\" style=\"text-decoration:none; margin-left:15px;\">取消置顶</a>";
                            // }
                            return html;
                        }
                    }

                ],
                //CompleteWorkTaskStatusAsync
                fixedColumns: {
                    leftColumns: 2,  //开启左侧两列固定
                    rightColumns: 1 //开启右侧1列固定
                },
                //rowCallback: RowCallBack,
                oLanguage: { //国际化配置
                    sProcessing: "正在获取数据，请稍后...",
                    sLengthMenu: "显示 _MENU_ 条",
                    sZeroRecords: "没有您要搜索的内容",
                    sInfo: "从 _START_ 到  _END_ 条记录 总记录数为 _TOTAL_ 条",
                    sInfoEmpty: "记录数为0",
                    sInfoFiltered: "(全部记录数 _MAX_ 条)",
                    sInfoPostFix: "",
                    sSearch: "从当前数据中检索： ",
                    sUrl: "",
                    oPaginate: {
                        sFirst: "首页",
                        sPrevious: "上一页",
                        sNext: "下一页",
                        sLast: "尾页"
                    }
                }
            });


        }


        function backSetTask(id, row, wmsTaskCode) {
            console.log(id);
            layer.prompt({
                formType: 0,
                value: '',
                title: '请输入密码',
                area: ['240px', '180px'] //自定义文本域宽高
            }, function (value, index, elem) {
                if (value === '123456') {
                    var data = { 'id': id, 'palletCode': row, 'wmsTaskCode': wmsTaskCode };
                    SubmitFormForAjax("/historyworktaskinfo/backsettask", data, function (data) {
                        if (data.result) {
                            popupAlert('还原任务成功！请依据实际情况到任务列表修改任务！', 1, function () {
                                location.reload();//刷新页面
                            });
                        } else {
                            popupAlert(data.message, 2, function (data) {
                                layer.close(data);
                            });
                        }
                    }, true);
                } else {
                    popupAlert("密码错误", 2, function (data) {
                        layer.close(data);
                    });
                }

                layer.close(index);
            });
        }

    </script>
}

